package com.ship.common.business.mapping;

import bsh.EvalError;
import bsh.Interpreter;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ship.common.core.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Field;

/**
 * @author 31463
 */
public abstract class ContentProvider {
	
	@Autowired
	private SpringUtil springUtil;
	
	public void init(Object caller) {
		interpreter = new Interpreter();
		try {
			interpreter.set("spring", springUtil);
		} catch (EvalError e) {
		}
	}
	
	protected Interpreter interpreter;


	/*
	获取可选项,选项带 label 和 value 两个属性
	 */
	public abstract JSONArray getOptions(Field field);
	
	public JSONObject createOption(String value, String text) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("label", text);
		jsonObject.put("value", value);
		return jsonObject;
	}

	/*
	toJson 时 将标准存储格式转为中文
	 */
	public abstract Object convert(Object currentValue, Object root, Field field);
}
